﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_shipping_terms
{
    public DAL_tbl_shipping_terms()
    {

    }



    public List<tbl_shipping_terms> select(int SHIPPING_TERMS_ID)
    {
        List<tbl_shipping_terms> list = new List<tbl_shipping_terms>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select SHIPPING_TERMS_ID,SHIPPING_TERMS,IS_ACTIVE from tbl_shipping_terms where SHIPPING_TERMS_ID=@SHIPPING_TERMS_ID";
        cmd.Parameters.AddWithValue("@SHIPPING_TERMS_ID", SHIPPING_TERMS_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_shipping_terms()
            {
                SHIPPING_TERMS_ID = Convert.ToInt32(dr["SHIPPING_TERMS_ID"]),
                SHIPPING_TERMS = dr["SHIPPING_TERMS"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"])
            });
        }

        return list;
    }



    public List<tbl_shipping_terms> selectAll()
    {
        List<tbl_shipping_terms> list = new List<tbl_shipping_terms>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select SHIPPING_TERMS_ID,SHIPPING_TERMS,IS_ACTIVE from tbl_shipping_terms Order By SHIPPING_TERMS_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_shipping_terms()
            {
                SHIPPING_TERMS_ID = Convert.ToInt32(dr["SHIPPING_TERMS_ID"]),
                SHIPPING_TERMS = dr["SHIPPING_TERMS"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"])
            });
        }

        return list;
    }



    public int insert(String SHIPPING_TERMS, bool IS_ACTIVE)
    {
        int i = 0;
        string sql = @"Insert into tbl_shipping_terms(SHIPPING_TERMS, IS_ACTIVE)
                        values(@SHIPPING_TERMS, @IS_ACTIVE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SHIPPING_TERMS", SHIPPING_TERMS);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int SHIPPING_TERMS_ID, String SHIPPING_TERMS, bool IS_ACTIVE)
    {
        int i = 0;
        string sql = @"Update tbl_shipping_terms SET SHIPPING_TERMS=@SHIPPING_TERMS, IS_ACTIVE=@IS_ACTIVE WHERE SHIPPING_TERMS_ID=@SHIPPING_TERMS_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SHIPPING_TERMS_ID", SHIPPING_TERMS_ID);
        cmd.Parameters.AddWithValue("@SHIPPING_TERMS", SHIPPING_TERMS);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int SHIPPING_TERMS_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_shipping_terms WHERE SHIPPING_TERMS_ID=@SHIPPING_TERMS_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SHIPPING_TERMS_ID", SHIPPING_TERMS_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}